/*  header-comment
/*  file   : index
/*  author : arida
/*  date   : 2017-6-4 18:27:20
/*  last   : 2017-7-6 21:45:44
*/
import React, { Component } from "react";
import PropTypes from "prop-types";

import { List } from "@ali/ding-ui";
const Item = List.Item;

/**
 * 封装JSAPI
 */

function alertJSAPIDatePicker(value, onChange) {
  dd.biz.util.datepicker({
    format: "yyyy-MM-dd",
    value, //默认显示日期
    onSuccess: function(result) {
      onChange(result.value);
    }
  });
}
class DatePicker extends Component {
  constructor(props) {
    super(props);
  }
  static defaultProps = {
    required: false,
    label: ""
  };
  static propTypes = {
    required: PropTypes.bool,
    label: PropTypes.string,
    value: PropTypes.any,
    onChange: PropTypes.func,
    placeholder: PropTypes.string
  };
  render() {
    const { required, label, onChange, value, placeholder } = this.props;
    return (
      <Item
        arrow="horizontal"
        extra={value || placeholder || "请选择"}
        onClick={alertJSAPIDatePicker.bind(null, value, onChange)}
      >
        <span className={`step-one-${required ? "required" : "optional"}`}>
          *
        </span>
        <span className="label-left">{label}</span>
      </Item>
    );
  }
}

DatePicker.alertJSAPIDatePicker = alertJSAPIDatePicker;

export default DatePicker;
